package cn.kgc.layui.utils;

import cn.hutool.json.JSONUtil;

import javax.servlet.ServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author: mosin
 * @version: v1.0  2022/9/15
 */
public class WriteJsonUtil {

    public  static  void  writeJson(ServletResponse response,Object data) throws IOException {
        //将响应数据转为json   写出
        String s = JSONUtil.toJsonStr(data);
        response.setContentType("application/json;charset=utf-8");
        PrintWriter writer =response.getWriter();
        writer.write(s);
        writer.close();
    }

}
